package com.siwei.mes.entity.experiment.concreteAdmixture;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.Map;

/**
 * @Description: 外加剂-密度
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class ConcreteAdmixtureMd {
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "单项结论")
    private String dxjl = "";
    @ApiModelProperty(value = "生产厂家控制值1")
    private String sccjkzz1 = "";
    @ApiModelProperty(value = "生产厂家控制值2")
    private String sccjkzz2 = "";
    @ApiModelProperty(value = "比重瓶法信息")
    private ConcreteAdmixtureMd.BzpfInfo bzpInfo = new ConcreteAdmixtureMd.BzpfInfo();

    @ApiModelProperty(value = "紧密密度法信息")
    private ConcreteAdmixtureMd.JdmdInfo jmmdInfo = new ConcreteAdmixtureMd.JdmdInfo();

    @Data
    @Accessors(chain = true)
    @ApiModel("比重瓶法信息")
    public static class BzpfInfo {
        @ApiModelProperty(value = "干燥比重瓶质量")
        private String gzbzpzl = "";
        @ApiModelProperty(value = "装水后比重瓶质量")
        private String zshbzpzl = "";
        @ApiModelProperty(value = "体积")
        private String tj = "";
        @ApiModelProperty(value = "装外加剂后比重瓶质量")
        private String zwjjhbzpzl = "";
        @ApiModelProperty(value = "试验结果")//1
        private String syjg = "";
    }

    @Data
    @Accessors(chain = true)
    @ApiModel("精密密度法信息")
    public static class JdmdInfo {
        @ApiModelProperty(value = "试样1密度")
        private String sy1md = "";
        @ApiModelProperty(value = "试样2密度")
        private String sy2md = "";
        @ApiModelProperty(value = "密度平均值")
        private String mdpjz = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        ConcreteAdmixtureMd entity = new ConcreteAdmixtureMd();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, ConcreteAdmixtureMd.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, ConcreteAdmixtureMd.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        ConcreteAdmixtureMd entity = JsonUtils.getObject(objJson, ConcreteAdmixtureMd.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        ConcreteAdmixtureMd.BzpfInfo bzpInfo = entity.getBzpInfo();
        /*if (StringUtils.isBlank(bzpInfo.getSyjg()) || "null".equals(bzpInfo.getSyjg())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        ConcreteAdmixtureMd.JdmdInfo jmmdInfo = entity.getJmmdInfo();
        if (StringUtils.isBlank(jmmdInfo.getMdpjz()) || "null".equals(jmmdInfo.getMdpjz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        return null;
    }

    public static void setValue(ConcreteAdmixtureMd entity, Map<String, Object> data) {
        if (data.get("Conclusion") != null) {
            entity.setDxjl(data.get("Conclusion").toString());
        }
        ConcreteAdmixtureMd.JdmdInfo jmmdInfo = entity.getJmmdInfo();
        if (data.get("ALLMD") != null) {
            jmmdInfo.setMdpjz(data.get("ALLMD").toString());
        }
        if (data.get("CMD") != null) {
            jmmdInfo.setSy1md(data.get("CMD").toString());
        }
        if (data.get("CMDCOPY") != null) {
            jmmdInfo.setSy2md(data.get("CMDCOPY").toString());
        }
        entity.setJmmdInfo(jmmdInfo);
    }
}
